import 'package:equatable/equatable.dart';

/// 笔记类型枚举
enum NoteType {
  general('GENERAL', '通用'),
  meeting('MEETING', '会议'),
  solution('SOLUTION', '解决方案'),
  issue('ISSUE', '问题');

  const NoteType(this.code, this.description);
  final String code;
  final String description;

  static NoteType fromCode(String code) {
    return NoteType.values.firstWhere(
      (type) => type.code == code,
      orElse: () => NoteType.general,
    );
  }
}

/// 笔记实体类
class Note extends Equatable {
  final int id;
  final int? projectId;
  final int? todoId;
  final String title;
  final String content;
  final NoteType noteType;
  final List<String> tags;
  final int authorId;
  final bool isPublic;
  final DateTime createTime;
  final DateTime updateTime;

  const Note({
    required this.id,
    this.projectId,
    this.todoId,
    required this.title,
    required this.content,
    this.noteType = NoteType.general,
    required this.tags,
    required this.authorId,
    this.isPublic = false,
    required this.createTime,
    required this.updateTime,
  });

  Note copyWith({
    int? id,
    int? projectId,
    int? todoId,
    String? title,
    String? content,
    NoteType? noteType,
    List<String>? tags,
    int? authorId,
    bool? isPublic,
    DateTime? createTime,
    DateTime? updateTime,
  }) {
    return Note(
      id: id ?? this.id,
      projectId: projectId ?? this.projectId,
      todoId: todoId ?? this.todoId,
      title: title ?? this.title,
      content: content ?? this.content,
      noteType: noteType ?? this.noteType,
      tags: tags ?? this.tags,
      authorId: authorId ?? this.authorId,
      isPublic: isPublic ?? this.isPublic,
      createTime: createTime ?? this.createTime,
      updateTime: updateTime ?? this.updateTime,
    );
  }

  @override
  List<Object?> get props => [
        id,
        projectId,
        todoId,
        title,
        content,
        noteType,
        tags,
        authorId,
        isPublic,
        createTime,
        updateTime,
      ];
}